/*===========================================================================
FILE: CRandGen.h

A random number generator.
===========================================================================*/
#ifndef __CRANDGEN_H__
#define __CRANDGEN_H__


#include "stdTypes.h"


/* Period parameters */  
#define RANDGEN_N 624
#define RANDGEN_M 397
#define RANDGEN_MATRIX_A 0x9908b0dfUL   /* constant vector a */
#define RANDGEN_UPPER_MASK 0x80000000UL /* most significant w-r bits */
#define RANDGEN_LOWER_MASK 0x7fffffffUL /* least significant r bits */


class CRandGen 
{
public:
	                         CRandGen();
	virtual                  ~CRandGen();

	/* initializes mt[N] with a seed */
	void                     Seed( uint32 seed );

	/* generates a random number on [0,0xffffffff]-interval */
	uint32                   Generate();

	/* generates a random number on [0,upperLimit)-interval */
	int32                   GetRand( uint32 upperLimit );
    /* generates a random number on [lowerlimit,upperLimit]-interval */
	int32                   GetRandRange( int32 lowerlimit, uint32 upperLimit );

protected:
	int                      m_mti;           /* mti==N+1 means mt[N] is not initialized */
    uint32                   m_mag01[2];      /* mag01[x] = x * MATRIX_A  for x=0,1 */
	uint32                   m_mt[RANDGEN_N];         /* the array for the state vector  */
};


#endif	// #ifndef __CRANDGEN_H__
